package com.zhx.threadcoreknowledge.synchromized;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author ：zhanghaixuan
 * @date ：Created in 2019-10-02 12:02
 * 用途         ： 锁试验
 */
public class SynchronizedTolock13 {
    Lock lock = new ReentrantLock();

    private synchronized void method1(){
        System.out.println("我是 synchronized 形式的锁");
    }

    public void method2(){
        lock.lock();

        try {
            System.out.println("我是lock形式的锁");
        }finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) {
        SynchronizedTolock13 synchronizedTolock13 = new SynchronizedTolock13();
        synchronizedTolock13.method1();
        synchronizedTolock13.method2();
    }
}
